<!DOCTYPE html>
<html>
<head>
    <title>stop修饰符演示</title>
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <style>
        .outer {
            padding: 50px;
            background: #ff6b6b;
            border-radius: 10px;
            margin: 20px;
        }
        .middle {
            padding: 30px;
            background: #4ecdc4;
            border-radius: 8px;
        }
        .inner {
            padding: 20px;
            background: #45b7d1;
            border-radius: 6px;
            color: white;
            text-align: center;
        }
        .log {
            margin: 20px;
            padding: 10px;
            background: #f8f9fa;
            border: 1px solid #dee2e6;
            border-radius: 5px;
            max-height: 200px;
            overflow-y: auto;
        }
        .log-item {
            padding: 2px 0;
            border-bottom: 1px solid #eee;
        }
    </style>
</head>
<body>
    <div id="app">
        <h2>事件冒泡控制演示</h2>
        
        <h3>不使用.stop修饰符</h3>
        <div class="outer" @click="logEvent('外层div')">
            外层div
            <div class="middle" @click="logEvent('中层div')">
                中层div
                <div class="inner" @click="logEvent('内层div')">
                    点击我（会冒泡）
                </div>
            </div>
        </div>
        
        <h3>使用.stop修饰符</h3>
        <div class="outer" @click="logEvent('外层div')">
            外层div
            <div class="middle" @click="logEvent('中层div')">
                中层div
                <div class="inner" @click.stop="logEvent('内层div')">
                    点击我（阻止冒泡）
                </div>
            </div>
        </div>
        
        <div class="log">
            <h4>事件日志：</h4>
            <div v-for="log in eventLogs" :key="log.id" class="log-item">
                {{ log.timestamp }} - {{ log.message }}
            </div>
            <button @click="clearLogs">清空日志</button>
        </div>
    </div>

    <script>
        const { createApp, ref } = Vue;
        
        createApp({
            setup() {
                const eventLogs = ref([]);
                let logId = 1;
                
                const logEvent = (element) => {
                    eventLogs.value.unshift({
                        id: logId++,
                        timestamp: new Date().toLocaleTimeString(),
                        message: `${element} 被点击`
                    });
                    
                    if (eventLogs.value.length > 20) {
                        eventLogs.value.pop();
                    }
                };
                
                const clearLogs = () => {
                    eventLogs.value = [];
                };
                
                return {
                    eventLogs,
                    logEvent,
                    clearLogs
                };
            }
        }).mount('#app');
    </script>
</body>
</html>
